<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var arr = [28, 5, 11, 9, 2, 35, 18, 15];
    document.write(arr);
    document.write("<br\>");
    function quickSort(arr, startIndex, endIndex) {
        if (startIndex >= endIndex) {
            return;
        }
        var pId = partition(arr, startIndex, endIndex);
        quickSort(arr, startIndex, pId - 1);
        quickSort(arr, pId + 1, endIndex);
    }

    function partition(arr, startIndex, endIndex) {
        var partition = arr[startIndex];
        var start = startIndex;
        while (!(startIndex === endIndex)) {
            while ((startIndex < endIndex) && (arr[endIndex] > partition)) {
                endIndex--;
            }
            while ((startIndex < endIndex) && (arr[startIndex] <= partition)) {
                startIndex++;
            }
            if (startIndex < endIndex) {
                var temp = arr[endIndex];
                arr[endIndex] = arr[startIndex];
                arr[startIndex] = temp;
            }
        }
        arr[start] = arr[endIndex];
        arr[endIndex] = partition;
        return endIndex;
    }

    quickSort(arr, 0, arr.length - 1);
    document.write(arr);
</script>
</body>
</html>